package com.dyz.wsw.domain.market.controller;


import com.dyz.wsw.domain.market.service.MarketService;
import com.dyz.wsw.common.web.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * @author dyz
 * Time 2024/6/9 19:55
 */
@RestController
@RequestMapping("/market/card")
public class MarketCardController {

    private final MarketService marketService;

    @Autowired
    public MarketCardController(MarketService marketService){
        this.marketService = marketService;
    }

    /**
     * 根据目录id查询当前目录下所属的所有卡片
     * @param cId 目录id
     * @param currentPage 请求页
     * @param requestCount 请求行数
     * @return 当前目录下所属的所有卡片的分页对象
     */
    @GetMapping("/by/{cId}/{currentPage}/{requestCount}")
    public Mono<JsonResult> getCardsByCID(@PathVariable Long cId, @PathVariable Integer currentPage, @PathVariable Integer requestCount){
        return marketService.getCardsByCId(cId,currentPage,requestCount)
                .map(JsonResult::ok);
    }


    /**
     * 查询所有目录信息
     * @return 所有的目录
     */
    @GetMapping("/categories")
    public Mono<JsonResult> findAllCategory(){
        return marketService.findAllCategory()
                .map(JsonResult::ok);
    }

    /**
     * 获取随机数量的卡片
     * @param count 请求数量
     * @return 卡片集
     */
    @GetMapping("/random/{count}")
    public Mono<JsonResult> getRandomCards(@PathVariable Integer count){
        return marketService.getRandomCards(count)
                .map(JsonResult::ok);
    }
}
